Load all required libraries.
library(tidyverse)
## -- Attaching packages --------------------------------------- tidyverse 1.3.1 --
## v ggplot2 3.3.5 v purrr 0.3.4
## v tibble 3.1.6 v dplyr 1.0.8
## v tidyr 1.2.0 v stringr 1.4.0
## v readr 2.1.2 v forcats 0.5.1
## -- Conflicts ------------------------------------------ tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag() masks stats::lag()
library(plotly)
##
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
##
## last_plot
## The following object is masked from 'package:stats':
##
## filter
## The following object is masked from 'package:graphics':
##
## layout
library(broom)
Read in raw data from RDS.
raw_data <- readRDS("./n1_n2_cleaned_cases.rds")
Make a few small modifications to names and data for visualizations.
final_data <- raw_data %>% mutate(log_copy_per_L = log10(mean_copy_num_L)) %>%
rename(Facility = wrf) %>%
mutate(Facility = recode(Facility,
"NO" = "WRF A",
"MI" = "WRF B",
"CC" = "WRF C"))
Seperate the data by gene target to ease layering in the final plot
#make three data layers
only_positives <<- subset(final_data, (!is.na(final_data$Facility)))
only_n1 <- subset(only_positives, target == "N1")
only_n2 <- subset(only_positives, target == "N2")
only_background <<-final_data %>%
select(c(date, cases_cum_clarke, new_cases_clarke, X7_day_ave_clarke)) %>%
group_by(date) %>% summarise_if(is.numeric, mean)
#specify fun colors
background_color <- "#7570B3"
seven_day_ave_color <- "#E6AB02"
marker_colors <- c("N1" = '#1B9E77',"N2" ='#D95F02')
#remove facilty C for now
#only_n1 <- only_n1[!(only_n1$Facility == "WRF C"),]
#only_n2 <- only_n2[!(only_n2$Facility == "WRF C"),]
only_n1 <- only_n1[!(only_n1$Facility == "WRF A" & only_n1$date == "2020-11-02"), ]
only_n2 <- only_n2[!(only_n2$Facility == "WRF A" & only_n2$date == "2020-11-02"), ]
Build the main plot
#first layer is the background epidemic curve
p1 <- only_background %>%
plotly::plot_ly() %>%
plotly::add_trace(x = ~date, y = ~new_cases_clarke,
type = "bar",
hoverinfo = "text",
text = ~paste('</br> Date: ', date,
'</br> Daily Cases: ', new_cases_clarke),
alpha = 0.5,
name = "Daily Reported Cases",
color = background_color,
colors = background_color,
showlegend = FALSE) %>%
layout(yaxis = list(title = "Clarke County Daily Cases", showline=TRUE)) %>%
layout(legend = list(orientation = "h", x = 0.2, y = -0.3))
#renders the main plot layer two as seven day moving average
p1 <- p1 %>% plotly::add_trace(x = ~date, y = ~X7_day_ave_clarke,
type = "scatter",
mode = "lines",
hoverinfo = "text",
text = ~paste('</br> Date: ', date,
'</br> Seven-Day Moving Average: ', X7_day_ave_clarke),
name = "Seven Day Moving Average Athens",
line = list(color = seven_day_ave_color),
showlegend = FALSE)
#renders the main plot layer three as positive target hits
p2 <- plotly::plot_ly() %>%
plotly::add_trace(x = ~date, y = ~mean_copy_num_L,
type = "scatter",
mode = "markers",
hoverinfo = "text",
text = ~paste('</br> Date: ', date,
'</br> Facility: ', Facility,
'</br> Target: ', target,
'</br> Copies/L: ', round(mean_copy_num_L, digits = 2)),
data = only_n1,
symbol = ~Facility,
marker = list(color = '#1B9E77', size = 8, opacity = 0.65),
showlegend = FALSE) %>%
plotly::add_trace(x = ~date, y = ~mean_copy_num_L,
type = "scatter",
mode = "markers",
hoverinfo = "text",
text = ~paste('</br> Date: ', date,
'</br> Facility: ', Facility,
'</br> Target: ', target,
'</br> Copies/L: ', round(mean_copy_num_L, digits = 2)),
data = only_n2,
symbol = ~Facility,
marker = list(color = '#D95F02', size = 8, opacity = 0.65),
showlegend = FALSE) %>%
layout(yaxis = list(title = "SARS CoV-2 Copies/L",
showline = TRUE,
type = "log",
dtick = 1,
automargin = TRUE)) %>%
layout(legend = list(orientation = "h", x = 0.2, y = -0.3))
#adds the limit of detection dashed line
p2 <- p2 %>% plotly::add_segments(x = as.Date("2020-03-14"),
xend = ~max(date + 10),
y = 3571.429, yend = 3571.429,
opacity = 0.35,
line = list(color = "black", dash = "dash")) %>%
layout(annotations = list(x = as.Date("2020-03-28"), y = 3.8, xref = "x", yref = "y",
text = "Limit of Detection", showarrow = FALSE))
p1
p2
Combine the two main plot pieces as a subplot
#seperate n1 and n2 frames by site
#n1
wrf_a_only_n1 <- subset(only_n1, Facility == "WRF A")
wrf_b_only_n1 <- subset(only_n1, Facility == "WRF B")
wrf_c_only_n1 <- subset(only_n1, Facility == "WRF C")
#n2
wrf_a_only_n2 <- subset(only_n2, Facility == "WRF A")
wrf_b_only_n2 <- subset(only_n2, Facility == "WRF B")
wrf_c_only_n2 <- subset(only_n2, Facility == "WRF C")
#rejoin the old data frames then seperate in to averages for each plant.
wrfa_both <- full_join(wrf_a_only_n1, wrf_a_only_n2)%>%
select(c(date, mean_total_copies)) %>%
group_by(date) %>%
summarize_if(is.numeric, mean) %>%
ungroup() %>%
mutate(log_total_copies_both = log10(mean_total_copies))
## Joining, by = c("date", "new_cases_clarke", "cases_cum_clarke",
## "X7_day_ave_clarke", "Facility", "collection_num", "target",
## "mean_copy_num_uL_rxn", "mean_copy_num_L", "sd_L", "se_L", "mean_total_copies",
## "sd_total_copies", "lo_95", "up_95", "log_copy_per_L")
wrfb_both <- full_join(wrf_b_only_n1, wrf_b_only_n2)%>%
select(c(date, mean_total_copies)) %>%
group_by(date) %>%
summarize_if(is.numeric, mean) %>%
ungroup() %>%
mutate(log_total_copies_both = log10(mean_total_copies))
## Joining, by = c("date", "new_cases_clarke", "cases_cum_clarke",
## "X7_day_ave_clarke", "Facility", "collection_num", "target",
## "mean_copy_num_uL_rxn", "mean_copy_num_L", "sd_L", "se_L", "mean_total_copies",
## "sd_total_copies", "lo_95", "up_95", "log_copy_per_L")
wrfc_both <- full_join(wrf_c_only_n1, wrf_c_only_n2)%>%
select(c(date, mean_total_copies)) %>%
group_by(date) %>%
summarize_if(is.numeric, mean) %>%
ungroup() %>%
mutate(log_total_copies_both = log10(mean_total_copies))
## Joining, by = c("date", "new_cases_clarke", "cases_cum_clarke",
## "X7_day_ave_clarke", "Facility", "collection_num", "target",
## "mean_copy_num_uL_rxn", "mean_copy_num_L", "sd_L", "se_L", "mean_total_copies",
## "sd_total_copies", "lo_95", "up_95", "log_copy_per_L")
#get max date
maxdate <- max(wrfa_both$date)
mindate <- min(wrfa_both$date)
Build loess smoothing figures figures
This makes the individual plots
#**************************************WRF A PLOT**********************************************
#add trendlines
#extract data from geom_smooth
#both extract
# *********************************span 0.6***********************************
#*****************Must always update the n = TOTAL NUMBER OF DAYS*************************
extract_botha <- ggplot(wrfa_both, aes(x = date, y = log_total_copies_both)) +
stat_smooth(aes(outfit=fit_botha<<-..y..), method = "loess", color = '#1B9E77',
span = 0.25, n = 695)
## Warning: Ignoring unknown aesthetics: outfit
#look at the fits to align dates and total observations
#both
extract_botha
## `geom_smooth()` using formula 'y ~ x'
fit_botha
## [1] 12.99515 12.99318 12.99125 12.98934 12.98746 12.98559 12.98375 12.98193
## [9] 12.98012 12.97832 12.97654 12.97476 12.97299 12.97122 12.96946 12.96769
## [17] 12.96591 12.96413 12.96235 12.96055 12.95874 12.95691 12.95506 12.95319
## [25] 12.95130 12.94938 12.94744 12.94546 12.94346 12.94141 12.93933 12.93721
## [33] 12.93505 12.93284 12.93058 12.92828 12.92591 12.92347 12.92096 12.91839
## [41] 12.91576 12.91309 12.91037 12.90762 12.90484 12.90203 12.89920 12.89636
## [49] 12.89352 12.89067 12.88782 12.88499 12.88217 12.87938 12.87662 12.87389
## [57] 12.87120 12.86856 12.86597 12.86344 12.86097 12.85858 12.85626 12.85402
## [65] 12.85187 12.84982 12.84786 12.84602 12.84428 12.84267 12.84117 12.83959
## [73] 12.83769 12.83550 12.83304 12.83033 12.82738 12.82421 12.82083 12.81727
## [81] 12.81354 12.80966 12.80565 12.80153 12.79730 12.79300 12.78863 12.78422
## [89] 12.77978 12.77534 12.77089 12.76648 12.76210 12.75779 12.75355 12.74941
## [97] 12.74539 12.74149 12.73774 12.73415 12.73075 12.72755 12.72456 12.72181
## [105] 12.71932 12.71709 12.71515 12.71352 12.71221 12.71124 12.71063 12.71039
## [113] 12.71055 12.71108 12.71196 12.71316 12.71468 12.71650 12.71861 12.72100
## [121] 12.72366 12.72656 12.72971 12.73307 12.73666 12.74044 12.74441 12.74856
## [129] 12.75287 12.75732 12.76192 12.76663 12.77146 12.77639 12.78140 12.78649
## [137] 12.79163 12.79682 12.80204 12.80729 12.81386 12.82288 12.83412 12.84733
## [145] 12.86225 12.87864 12.89625 12.91484 12.93415 12.95394 12.97395 12.99395
## [153] 13.01369 13.03291 13.05137 13.06882 13.08501 13.09969 13.11262 13.12356
## [161] 13.13224 13.14066 13.15084 13.16257 13.17563 13.18982 13.20493 13.22073
## [169] 13.23703 13.25361 13.27026 13.28677 13.30293 13.31853 13.33335 13.34719
## [177] 13.35983 13.37107 13.38069 13.38849 13.39424 13.39775 13.40008 13.40240
## [185] 13.40467 13.40685 13.40889 13.41074 13.41236 13.41369 13.41470 13.41533
## [193] 13.41555 13.41529 13.41453 13.41320 13.41128 13.40870 13.40542 13.40139
## [201] 13.39658 13.39093 13.38439 13.37693 13.36849 13.35903 13.34849 13.33685
## [209] 13.32404 13.31002 13.29336 13.27295 13.24928 13.22282 13.19402 13.16336
## [217] 13.13132 13.09836 13.06495 13.03157 12.99867 12.96674 12.93624 12.90765
## [225] 12.88143 12.85805 12.83442 12.80739 12.77732 12.74459 12.70956 12.67261
## [233] 12.63412 12.59444 12.55395 12.51302 12.47202 12.43132 12.39130 12.35232
## [241] 12.31475 12.27897 12.24534 12.21424 12.18604 12.16110 12.13980 12.12125
## [249] 12.10421 12.08856 12.07419 12.06097 12.04879 12.03752 12.02704 12.01724
## [257] 12.00798 11.99916 11.99065 11.98232 11.97407 11.96576 11.95729 11.94852
## [265] 11.93934 11.92962 11.92085 11.91445 11.91017 11.90778 11.90705 11.90775
## [273] 11.90964 11.91249 11.91607 11.92013 11.92446 11.92882 11.93296 11.93667
## [281] 11.93970 11.94183 11.94282 11.94243 11.94044 11.93660 11.93070 11.92409
## [289] 11.91824 11.91303 11.90834 11.90404 11.90002 11.89617 11.89235 11.88845
## [297] 11.88436 11.87995 11.87510 11.86970 11.86362 11.85675 11.84896 11.83985
## [305] 11.82917 11.81710 11.80379 11.78940 11.77411 11.75808 11.74146 11.72442
## [313] 11.70712 11.68973 11.67241 11.65533 11.63864 11.62250 11.60709 11.59257
## [321] 11.57909 11.56682 11.55593 11.54658 11.53642 11.52329 11.50760 11.48974
## [329] 11.47013 11.44917 11.42726 11.40482 11.38224 11.35993 11.33830 11.31775
## [337] 11.29869 11.28153 11.26666 11.25451 11.24546 11.23992 11.23831 11.23918
## [345] 11.24079 11.24316 11.24628 11.25016 11.25481 11.26021 11.26638 11.27332
## [353] 11.28103 11.28952 11.29877 11.30881 11.31962 11.33121 11.34359 11.35814
## [361] 11.37604 11.39698 11.42068 11.44683 11.47513 11.50528 11.53698 11.56993
## [369] 11.60384 11.63840 11.67331 11.70828 11.74300 11.77717 11.81050 11.84269
## [377] 11.87343 11.90242 11.92937 11.95398 11.97914 12.00771 12.03930 12.07353
## [385] 12.11001 12.14838 12.18823 12.22920 12.27091 12.31296 12.35498 12.39658
## [393] 12.43739 12.47702 12.51510 12.55123 12.58504 12.61615 12.64417 12.66872
## [401] 12.68943 12.70848 12.72822 12.74849 12.76911 12.78994 12.81079 12.83151
## [409] 12.85193 12.87189 12.89123 12.90977 12.92736 12.94384 12.95903 12.97277
## [417] 12.98490 12.99525 13.00366 13.00997 13.01370 13.01464 13.01300 13.00903
## [425] 13.00295 12.99499 12.98538 12.97434 12.96211 12.94891 12.93496 12.92051
## [433] 12.90577 12.89098 12.87636 12.86214 12.84855 12.83582 12.82417 12.81384
## [441] 12.80506 12.79517 12.78170 12.76513 12.74596 12.72467 12.70174 12.67766
## [449] 12.65292 12.62800 12.60338 12.57956 12.55702 12.53623 12.51770 12.50190
## [457] 12.48933 12.47789 12.46529 12.45168 12.43718 12.42196 12.40616 12.38991
## [465] 12.37336 12.35667 12.33996 12.32339 12.30711 12.29125 12.27596 12.26138
## [473] 12.24767 12.23496 12.22339 12.21312 12.20429 12.19704 12.19071 12.18457
## [481] 12.17865 12.17298 12.16761 12.16255 12.15784 12.15352 12.14962 12.14617
## [489] 12.14320 12.14075 12.13885 12.13753 12.13682 12.13676 12.13738 12.13871
## [497] 12.14079 12.14415 12.14920 12.15581 12.16383 12.17310 12.18349 12.19484
## [505] 12.20701 12.21985 12.23322 12.24696 12.26093 12.27499 12.28899 12.30277
## [513] 12.31620 12.32913 12.34141 12.35289 12.36343 12.37287 12.38368 12.39805
## [521] 12.41545 12.43534 12.45719 12.48048 12.50467 12.52922 12.55362 12.57732
## [529] 12.59979 12.62051 12.63893 12.65454 12.66679 12.67516 12.68183 12.68924
## [537] 12.69730 12.70592 12.71498 12.72440 12.73406 12.74388 12.75374 12.76356
## [545] 12.77322 12.78263 12.79169 12.80030 12.80836 12.81576 12.82241 12.82821
## [553] 12.83306 12.83685 12.83949 12.84087 12.84090 12.83948 12.83649 12.83186
## [561] 12.82547 12.81722 12.80632 12.79226 12.77536 12.75593 12.73429 12.71076
## [569] 12.68566 12.65932 12.63204 12.60415 12.57597 12.54782 12.52001 12.49286
## [577] 12.46670 12.44184 12.41860 12.39730 12.37826 12.35811 12.33360 12.30518
## [585] 12.27334 12.23854 12.20126 12.16195 12.12110 12.07918 12.03665 11.99398
## [593] 11.95166 11.91013 11.86989 11.83139 11.79512 11.76153 11.73110 11.70430
## [601] 11.68161 11.66348 11.64792 11.63265 11.61774 11.60324 11.58921 11.57571
## [609] 11.56281 11.55056 11.53903 11.52827 11.51835 11.50933 11.50127 11.49422
## [617] 11.48825 11.48343 11.48001 11.47815 11.47775 11.47870 11.48091 11.48427
## [625] 11.48867 11.49402 11.50020 11.50712 11.51468 11.52276 11.53127 11.54011
## [633] 11.54916 11.55833 11.56752 11.57662 11.58552 11.59413 11.60234 11.61075
## [641] 11.61997 11.63000 11.64079 11.65232 11.66454 11.67745 11.69099 11.70514
## [649] 11.71987 11.73516 11.75095 11.76724 11.78398 11.80115 11.81870 11.83663
## [657] 11.85488 11.87343 11.89244 11.91207 11.93230 11.95314 11.97457 11.99657
## [665] 12.01914 12.04226 12.06593 12.09013 12.11486 12.14009 12.16583 12.19206
## [673] 12.21876 12.24594 12.27357 12.30165 12.33016 12.35910 12.38845 12.41815
## [681] 12.44814 12.47846 12.50911 12.54012 12.57150 12.60329 12.63550 12.66814
## [689] 12.70124 12.73483 12.76891 12.80351 12.83864 12.87434 12.91062
#assign fits to a vector
both_trenda <- fit_botha
#extract y min and max for each
limits_botha <- ggplot_build(extract_botha)$data
## `geom_smooth()` using formula 'y ~ x'
limits_botha <- as.data.frame(limits_botha)
both_ymina <- limits_botha$ymin
both_ymaxa <- limits_botha$ymax
#reassign dataframes (just to be safe)
work_botha <- wrfa_both
#fill in missing dates to smooth fits
work_botha <- work_botha %>% complete(date = seq(min(date), max(date), by = "1 day"))
date_vec_botha <- work_botha$date
#create a new smooth dataframe to layer
smooth_frame_botha <- data.frame(date_vec_botha, both_trenda, both_ymina, both_ymaxa)
#WRF A
#plot smooth frames
p_wrf_a <- plotly::plot_ly() %>%
plotly::add_lines(x = ~date_vec_botha, y = ~both_trenda,
data = smooth_frame_botha,
hoverinfo = "text",
text = ~paste('</br> Date: ', date_vec_botha,
'</br> Median Log Copies: ', round(both_trenda, digits = 2)),
line = list(color = '#1B9E77', size = 8, opacity = 0.65),
showlegend = FALSE) %>%
layout(xaxis = list(range = c(mindate - 7, maxdate + 7))) %>% #buffer here
plotly::add_ribbons(x ~date_vec_botha, ymin = ~both_ymina, ymax = ~both_ymaxa,
showlegend = FALSE,
opacity = 0.25,
hoverinfo = "text",
text = ~paste('</br> Date: ', date_vec_botha, #leaving in case we want to change
'</br> Max Log Copies: ', round(both_ymaxa, digits = 2),
'</br> Min Log Copies: ', round(both_ymina, digits = 2)),
name = "",
fillcolor = '#1B9E77',
line = list(color = '#1B9E77')) %>%
layout(yaxis = list(title = "Total Log10 SARS CoV-2 Copies",
showline = TRUE,
automargin = TRUE)) %>%
layout(xaxis = list(title = "Date")) %>%
layout(title = "WRF A") %>%
plotly::add_markers(x = ~date, y = ~log_total_copies_both,
data = wrfa_both,
hoverinfo = "text",
showlegend = FALSE,
text = ~paste('</br> Date: ', date,
'</br> Actual Log Copies: ', round(log_total_copies_both, digits = 2)),
marker = list(color = '#1B9E77', size = 6, opacity = 0.65))
p_wrf_a
save(p_wrf_a, file = "./plotly_objs/p_wrf_a.rda")
#**************************************WRF B PLOT**********************************************
#add trendlines
#extract data from geom_smooth
#both extract
# *********************************span 0.6***********************************
#*****************Must always update the n = TOTAL NUMBER OF DAYS*************************
extract_bothb <- ggplot(wrfb_both, aes(x = date, y = log_total_copies_both)) +
stat_smooth(aes(outfit=fit_bothb<<-..y..), method = "loess", color = '#D95F02',
span = 0.25, n = 695)
## Warning: Ignoring unknown aesthetics: outfit
#look at the fits to align dates and total observations
#both
extract_bothb
## `geom_smooth()` using formula 'y ~ x'
fit_bothb
## [1] 12.61240 12.60847 12.60463 12.60088 12.59722 12.59364 12.59014 12.58673
## [9] 12.58340 12.58014 12.57696 12.57386 12.57083 12.56786 12.56497 12.56214
## [17] 12.55938 12.55668 12.55404 12.55147 12.54894 12.54648 12.54407 12.54170
## [25] 12.53939 12.53713 12.53491 12.53274 12.53061 12.52852 12.52647 12.52445
## [33] 12.52247 12.52053 12.51861 12.51672 12.51484 12.51294 12.51103 12.50912
## [41] 12.50721 12.50530 12.50341 12.50154 12.49970 12.49788 12.49611 12.49437
## [49] 12.49269 12.49106 12.48950 12.48800 12.48658 12.48523 12.48397 12.48281
## [57] 12.48174 12.48077 12.47991 12.47917 12.47855 12.47806 12.47770 12.47749
## [65] 12.47741 12.47749 12.47773 12.47813 12.47869 12.47944 12.48036 12.48141
## [73] 12.48252 12.48369 12.48493 12.48623 12.48760 12.48904 12.49055 12.49213
## [81] 12.49379 12.49552 12.49734 12.49923 12.50120 12.50326 12.50540 12.50762
## [89] 12.50994 12.51235 12.51484 12.51743 12.52012 12.52290 12.52579 12.52877
## [97] 12.53185 12.53504 12.53833 12.54173 12.54524 12.54886 12.55260 12.55644
## [105] 12.56041 12.56449 12.56869 12.57301 12.57745 12.58202 12.58671 12.59153
## [113] 12.59648 12.60141 12.60618 12.61080 12.61530 12.61970 12.62403 12.62829
## [121] 12.63252 12.63673 12.64095 12.64519 12.64948 12.65384 12.65829 12.66284
## [129] 12.66753 12.67236 12.67737 12.68257 12.68799 12.69364 12.69955 12.70676
## [137] 12.71617 12.72757 12.74073 12.75544 12.77150 12.78868 12.80677 12.82556
## [145] 12.84484 12.86438 12.88397 12.90341 12.92247 12.94094 12.95861 12.97526
## [153] 12.99068 13.00465 13.01696 13.02740 13.03851 13.05273 13.06965 13.08891
## [161] 13.11009 13.13282 13.15670 13.18133 13.20634 13.23132 13.25590 13.27967
## [169] 13.30224 13.32323 13.34224 13.35889 13.37278 13.38352 13.39073 13.39580
## [177] 13.40043 13.40458 13.40824 13.41140 13.41404 13.41615 13.41770 13.41869
## [185] 13.41909 13.41890 13.41809 13.41665 13.41457 13.41183 13.40841 13.40429
## [193] 13.39947 13.39393 13.38764 13.38060 13.37279 13.36420 13.35480 13.34458
## [201] 13.33352 13.32162 13.30885 13.29520 13.28065 13.26362 13.24281 13.21862
## [209] 13.19146 13.16175 13.12989 13.09629 13.06137 13.02554 12.98919 12.95275
## [217] 12.91662 12.88122 12.84695 12.81422 12.78344 12.75502 12.72938 12.70692
## [225] 12.68475 12.65991 12.63271 12.60346 12.57247 12.54004 12.50648 12.47211
## [233] 12.43722 12.40213 12.36714 12.33257 12.29871 12.26589 12.23440 12.20456
## [241] 12.17667 12.15104 12.12798 12.10779 12.09079 12.07640 12.06372 12.05257
## [249] 12.04281 12.03425 12.02673 12.02008 12.01414 12.00874 12.00370 11.99888
## [257] 11.99408 11.98916 11.98394 11.97825 11.97193 11.96698 11.96529 11.96654
## [265] 11.97040 11.97657 11.98471 11.99450 12.00563 12.01776 12.03058 12.04377
## [273] 12.05700 12.06996 12.08231 12.09375 12.10394 12.11257 12.11931 12.12384
## [281] 12.12584 12.12499 12.12316 12.12235 12.12239 12.12315 12.12447 12.12621
## [289] 12.12822 12.13035 12.13245 12.13437 12.13597 12.13710 12.13760 12.13734
## [297] 12.13616 12.13392 12.13046 12.12563 12.11930 12.11093 12.10024 12.08746
## [305] 12.07281 12.05651 12.03880 12.01989 12.00000 11.97938 11.95823 11.93678
## [313] 11.91526 11.89390 11.87291 11.85252 11.83295 11.81444 11.79720 11.78146
## [321] 11.76744 11.75537 11.74216 11.72496 11.70441 11.68111 11.65570 11.62878
## [329] 11.60098 11.57292 11.54522 11.51849 11.49335 11.47042 11.45033 11.43369
## [337] 11.42112 11.41325 11.40779 11.40215 11.39645 11.39078 11.38525 11.37999
## [345] 11.37510 11.37069 11.36686 11.36374 11.36142 11.36003 11.35966 11.36044
## [353] 11.36247 11.36585 11.37071 11.37715 11.38527 11.39600 11.40997 11.42691
## [361] 11.44652 11.46852 11.49263 11.51856 11.54603 11.57476 11.60446 11.63485
## [369] 11.66564 11.69655 11.72729 11.75759 11.78715 11.81569 11.84293 11.86859
## [377] 11.89238 11.91401 11.93606 11.96110 11.98880 12.01883 12.05087 12.08461
## [385] 12.11972 12.15588 12.19277 12.23006 12.26744 12.30459 12.34117 12.37687
## [393] 12.41138 12.44436 12.47549 12.50446 12.53094 12.55461 12.57515 12.59485
## [401] 12.61602 12.63838 12.66165 12.68554 12.70977 12.73406 12.75812 12.78167
## [409] 12.80442 12.82610 12.84642 12.86509 12.88183 12.89636 12.90839 12.91872
## [417] 12.92833 12.93722 12.94538 12.95282 12.95953 12.96551 12.97076 12.97528
## [425] 12.97907 12.98212 12.98443 12.98600 12.98684 12.98693 12.98628 12.98488
## [433] 12.98274 12.97985 12.97621 12.97182 12.96537 12.95576 12.94332 12.92837
## [441] 12.91122 12.89219 12.87161 12.84980 12.82707 12.80376 12.78016 12.75662
## [449] 12.73344 12.71095 12.68946 12.66931 12.65080 12.63426 12.62001 12.60563
## [457] 12.58871 12.56953 12.54838 12.52556 12.50136 12.47607 12.44999 12.42340
## [465] 12.39661 12.36989 12.34355 12.31787 12.29316 12.26969 12.24777 12.22769
## [473] 12.20973 12.19420 12.18138 12.17157 12.16260 12.15231 12.14096 12.12882
## [481] 12.11615 12.10323 12.09032 12.07769 12.06561 12.05435 12.04416 12.03533
## [489] 12.02811 12.02278 12.01960 12.01884 12.02032 12.02360 12.02857 12.03513
## [497] 12.04316 12.05255 12.06320 12.07500 12.08784 12.10161 12.11621 12.13151
## [505] 12.14742 12.16382 12.18061 12.19768 12.21491 12.23221 12.24945 12.26654
## [513] 12.28336 12.29981 12.31577 12.33114 12.34580 12.35966 12.37605 12.39787
## [521] 12.42433 12.45467 12.48809 12.52382 12.56106 12.59905 12.63699 12.67411
## [529] 12.70962 12.74274 12.77270 12.79870 12.81996 12.83572 12.84890 12.86293
## [537] 12.87766 12.89299 12.90880 12.92495 12.94134 12.95783 12.97432 12.99068
## [545] 13.00679 13.02252 13.03777 13.05240 13.06630 13.07935 13.09142 13.10241
## [553] 13.11217 13.12060 13.12758 13.13298 13.13669 13.13857 13.13852 13.13642
## [561] 13.13213 13.12555 13.11615 13.10368 13.08843 13.07068 13.05073 13.02886
## [569] 13.00535 12.98049 12.95457 12.92787 12.90068 12.87329 12.84598 12.81904
## [577] 12.79276 12.76741 12.74329 12.72069 12.69989 12.67765 12.65087 12.62002
## [585] 12.58558 12.54800 12.50778 12.46537 12.42126 12.37591 12.32979 12.28338
## [593] 12.23715 12.19157 12.14711 12.10425 12.06346 12.02520 11.98996 11.95820
## [601] 11.93039 11.90702 11.88495 11.86102 11.83558 11.80900 11.78164 11.75386
## [609] 11.72604 11.69852 11.67168 11.64588 11.62149 11.59886 11.57836 11.56036
## [617] 11.54522 11.53330 11.52388 11.51595 11.50944 11.50427 11.50037 11.49765
## [625] 11.49605 11.49549 11.49590 11.49719 11.49930 11.50214 11.50565 11.50974
## [633] 11.51435 11.51939 11.52480 11.53049 11.53639 11.54242 11.54852 11.55508
## [641] 11.56253 11.57085 11.58004 11.59007 11.60092 11.61258 11.62502 11.63824
## [649] 11.65220 11.66690 11.68232 11.69843 11.71522 11.73268 11.75077 11.76950
## [657] 11.78883 11.80875 11.82935 11.85073 11.87287 11.89577 11.91943 11.94383
## [665] 11.96899 11.99487 12.02150 12.04885 12.07691 12.10570 12.13519 12.16539
## [673] 12.19629 12.22787 12.26015 12.29310 12.32673 12.36103 12.39599 12.43156
## [681] 12.46769 12.50440 12.54169 12.57959 12.61811 12.65726 12.69706 12.73752
## [689] 12.77864 12.82046 12.86297 12.90620 12.95015 12.99485 13.04030
#assign fits to a vector
both_trendb <- fit_bothb
#extract y min and max for each
limits_bothb <- ggplot_build(extract_bothb)$data
## `geom_smooth()` using formula 'y ~ x'
limits_bothb <- as.data.frame(limits_bothb)
both_yminb <- limits_bothb$ymin
both_ymaxb <- limits_bothb$ymax
#reassign dataframes (just to be safe)
work_bothb <- wrfb_both
#fill in missing dates to smooth fits
work_bothb <- work_bothb %>% complete(date = seq(min(date), max(date), by = "1 day"))
date_vec_bothb <- work_bothb$date
#create a new smooth dataframe to layer
smooth_frame_bothb <- data.frame(date_vec_bothb, both_trendb, both_yminb, both_ymaxb)
#WRF B
#plot smooth frames
p_wrf_b <- plotly::plot_ly() %>%
plotly::add_lines(x = ~date_vec_bothb, y = ~both_trendb,
data = smooth_frame_bothb,
hoverinfo = "text",
text = ~paste('</br> Date: ', date_vec_bothb,
'</br> Median Log Copies: ', round(both_trendb, digits = 2)),
line = list(color = '#D95F02', size = 8, opacity = 0.65),
showlegend = FALSE) %>%
layout(xaxis = list(range = c(mindate - 7, maxdate + 7))) %>% #buffer here
plotly::add_ribbons(x ~date_vec_bothb, ymin = ~both_yminb, ymax = ~both_ymaxb,
showlegend = FALSE,
opacity = 0.25,
hoverinfo = "text",
text = ~paste('</br> Date: ', date_vec_bothb, #leaving in case we want to change
'</br> Max Log Copies: ', round(both_ymaxb, digits = 2),
'</br> Min Log Copies: ', round(both_yminb, digits = 2)),
name = "",
fillcolor = '#D95F02',
line = list(color = '#D95F02')) %>%
layout(yaxis = list(title = "Total Log10 SARS CoV-2 Copies",
showline = TRUE,
automargin = TRUE)) %>%
layout(xaxis = list(title = "Date")) %>%
layout(title = "WRF B") %>%
plotly::add_markers(x = ~date, y = ~log_total_copies_both,
data = wrfb_both,
hoverinfo = "text",
showlegend = FALSE,
text = ~paste('</br> Date: ', date,
'</br> Actual Log Copies: ', round(log_total_copies_both, digits = 2)),
marker = list(color = '#D95F02', size = 6, opacity = 0.65))
p_wrf_b
save(p_wrf_b, file = "./plotly_objs/p_wrf_b.rda")
#**************************************WRF C PLOT********************************************** #add trendlines #extract data from geom_smooth # *********************************span 0.6*********************************** #*****************Must always update the n = TOTAL NUMBER OF DAYS*************************
extract_bothc <- ggplot(wrfc_both, aes(x = date, y = log_total_copies_both)) +
stat_smooth(aes(outfit=fit_bothc<<-..y..), method = "loess", color = '#E7298A',
span = 0.25, n = 695)
## Warning: Ignoring unknown aesthetics: outfit
#look at the fits to align dates and total observations
#both
extract_bothc
## `geom_smooth()` using formula 'y ~ x'
fit_bothc
## [1] 11.98256 11.97944 11.97638 11.97338 11.97043 11.96752 11.96466 11.96185
## [9] 11.95907 11.95633 11.95363 11.95095 11.94830 11.94568 11.94308 11.94050
## [17] 11.93793 11.93537 11.93283 11.93029 11.92775 11.92521 11.92268 11.92013
## [25] 11.91758 11.91501 11.91243 11.90983 11.90721 11.90457 11.90190 11.89920
## [33] 11.89646 11.89369 11.89088 11.88803 11.88513 11.88218 11.87918 11.87613
## [41] 11.87302 11.86985 11.86662 11.86328 11.85982 11.85625 11.85257 11.84880
## [49] 11.84496 11.84104 11.83707 11.83306 11.82902 11.82495 11.82088 11.81681
## [57] 11.81276 11.80873 11.80474 11.80080 11.79693 11.79312 11.78941 11.78579
## [65] 11.78228 11.77889 11.77564 11.77252 11.76957 11.76678 11.76418 11.76176
## [73] 11.75955 11.75755 11.75578 11.75425 11.75297 11.75195 11.75088 11.74948
## [81] 11.74776 11.74574 11.74347 11.74095 11.73822 11.73530 11.73222 11.72900
## [89] 11.72567 11.72226 11.71878 11.71527 11.71175 11.70824 11.70478 11.70138
## [97] 11.69808 11.69490 11.69185 11.68898 11.68631 11.68385 11.68164 11.67970
## [105] 11.67806 11.67674 11.67576 11.67517 11.67497 11.67519 11.67587 11.67702
## [113] 11.67868 11.68086 11.68359 11.68690 11.69082 11.69536 11.70056 11.70644
## [121] 11.71350 11.72215 11.73225 11.74366 11.75625 11.76988 11.78443 11.79974
## [129] 11.81569 11.83215 11.84897 11.86602 11.88318 11.90029 11.91723 11.93386
## [137] 11.95005 11.96566 11.98056 11.99461 12.00994 12.02858 12.05018 12.07441
## [145] 12.10095 12.12947 12.15963 12.19111 12.22358 12.25670 12.29015 12.32359
## [153] 12.35670 12.38915 12.42061 12.45073 12.47921 12.50570 12.52988 12.55142
## [161] 12.56998 12.58793 12.60770 12.62905 12.65173 12.67550 12.70012 12.72533
## [169] 12.75091 12.77660 12.80216 12.82735 12.85193 12.87564 12.89826 12.91953
## [177] 12.93921 12.95706 12.97284 12.98630 12.99719 13.00528 13.01152 13.01701
## [185] 13.02175 13.02574 13.02895 13.03140 13.03307 13.03395 13.03404 13.03333
## [193] 13.03181 13.02948 13.02633 13.02236 13.01755 13.01190 13.00541 12.99806
## [201] 12.98985 12.98077 12.97082 12.95999 12.94827 12.93566 12.92215 12.90772
## [209] 12.89239 12.87613 12.85626 12.83063 12.80000 12.76516 12.72689 12.68595
## [217] 12.64313 12.59920 12.55493 12.51112 12.46852 12.42793 12.39011 12.35584
## [225] 12.32590 12.30107 12.27775 12.25201 12.22413 12.19440 12.16309 12.13049
## [233] 12.09687 12.06252 12.02771 11.99273 11.95786 11.92337 11.88955 11.85668
## [241] 11.82503 11.79489 11.76655 11.74027 11.71634 11.69504 11.67665 11.66059
## [249] 11.64602 11.63279 11.62079 11.60988 11.59994 11.59084 11.58244 11.57463
## [257] 11.56726 11.56022 11.55337 11.54658 11.53973 11.53269 11.52533 11.51752
## [265] 11.50912 11.50002 11.49218 11.48743 11.48547 11.48599 11.48867 11.49320
## [273] 11.49929 11.50661 11.51486 11.52372 11.53289 11.54205 11.55091 11.55913
## [281] 11.56643 11.57248 11.57698 11.57961 11.58007 11.57805 11.57323 11.56682
## [289] 11.56022 11.55347 11.54656 11.53953 11.53239 11.52516 11.51784 11.51047
## [297] 11.50306 11.49563 11.48818 11.48075 11.47335 11.46599 11.45870 11.44979
## [305] 11.43780 11.42304 11.40585 11.38655 11.36546 11.34292 11.31925 11.29477
## [313] 11.26982 11.24471 11.21978 11.19535 11.17175 11.14930 11.12833 11.10916
## [321] 11.09213 11.07755 11.06576 11.05708 11.04943 11.04064 11.03092 11.02047
## [329] 11.00949 10.99818 10.98674 10.97538 10.96430 10.95370 10.94378 10.93475
## [337] 10.92680 10.92014 10.91498 10.91150 10.90992 10.91044 10.91325 10.91850
## [345] 10.92603 10.93561 10.94701 10.96001 10.97435 10.98983 11.00620 11.02324
## [353] 11.04071 11.05838 11.07603 11.09342 11.11032 11.12650 11.14172 11.15781
## [361] 11.17655 11.19771 11.22103 11.24626 11.27316 11.30147 11.33095 11.36136
## [369] 11.39243 11.42392 11.45559 11.48718 11.51845 11.54915 11.57903 11.60784
## [377] 11.63533 11.66125 11.68536 11.70741 11.72927 11.75287 11.77800 11.80444
## [385] 11.83200 11.86046 11.88962 11.91927 11.94921 11.97923 12.00912 12.03867
## [393] 12.06768 12.09595 12.12326 12.14940 12.17418 12.19738 12.21880 12.23823
## [401] 12.25547 12.27203 12.28949 12.30766 12.32640 12.34554 12.36491 12.38435
## [409] 12.40370 12.42280 12.44148 12.45958 12.47694 12.49339 12.50877 12.52292
## [417] 12.53568 12.54687 12.55635 12.56394 12.56959 12.57342 12.57558 12.57619
## [425] 12.57540 12.57333 12.57013 12.56593 12.56085 12.55505 12.54865 12.54178
## [433] 12.53458 12.52719 12.51975 12.51237 12.50521 12.49840 12.49206 12.48634
## [441] 12.48137 12.47552 12.46726 12.45690 12.44475 12.43112 12.41631 12.40063
## [449] 12.38438 12.36789 12.35144 12.33535 12.31993 12.30547 12.29230 12.28072
## [457] 12.27103 12.26172 12.25117 12.23952 12.22690 12.21345 12.19930 12.18458
## [465] 12.16943 12.15399 12.13838 12.12276 12.10724 12.09196 12.07707 12.06269
## [473] 12.04895 12.03600 12.02397 12.01300 12.00321 11.99474 11.98643 11.97715
## [481] 11.96704 11.95627 11.94501 11.93341 11.92163 11.90984 11.89820 11.88686
## [489] 11.87600 11.86577 11.85633 11.84785 11.84049 11.83440 11.82975 11.82670
## [497] 11.82542 11.82544 11.82617 11.82760 11.82969 11.83241 11.83574 11.83964
## [505] 11.84409 11.84906 11.85451 11.86043 11.86678 11.87353 11.88065 11.88812
## [513] 11.89591 11.90399 11.91232 11.92089 11.92966 11.93860 11.94957 11.96410
## [521] 11.98170 12.00187 12.02412 12.04795 12.07285 12.09835 12.12393 12.14910
## [529] 12.17337 12.19623 12.21720 12.23577 12.25145 12.26375 12.27510 12.28817
## [537] 12.30281 12.31884 12.33610 12.35443 12.37366 12.39363 12.41418 12.43513
## [545] 12.45633 12.47760 12.49880 12.51974 12.54027 12.56023 12.57944 12.59774
## [553] 12.61497 12.63097 12.64557 12.65860 12.66990 12.67931 12.68666 12.69179
## [561] 12.69453 12.69472 12.69233 12.68758 12.68069 12.67187 12.66134 12.64933
## [569] 12.63604 12.62170 12.60652 12.59072 12.57452 12.55814 12.54178 12.52568
## [577] 12.51004 12.49509 12.48103 12.46810 12.45650 12.44362 12.42692 12.40679
## [585] 12.38362 12.35779 12.32967 12.29966 12.26812 12.23546 12.20204 12.16825
## [593] 12.13447 12.10109 12.06849 12.03704 12.00714 11.97916 11.95348 11.93049
## [601] 11.91057 11.89411 11.87870 11.86188 11.84392 11.82509 11.80567 11.78593
## [609] 11.76614 11.74657 11.72749 11.70918 11.69192 11.67596 11.66159 11.64908
## [617] 11.63870 11.63072 11.62472 11.62005 11.61661 11.61433 11.61310 11.61285
## [625] 11.61349 11.61493 11.61707 11.61984 11.62315 11.62690 11.63101 11.63540
## [633] 11.63997 11.64463 11.64930 11.65390 11.65833 11.66250 11.66633 11.67029
## [641] 11.67491 11.68017 11.68603 11.69247 11.69948 11.70702 11.71508 11.72362
## [649] 11.73264 11.74209 11.75196 11.76223 11.77287 11.78386 11.79517 11.80678
## [657] 11.81867 11.83081 11.84331 11.85630 11.86977 11.88372 11.89813 11.91300
## [665] 11.92833 11.94411 11.96034 11.97700 11.99410 12.01162 12.02956 12.04791
## [673] 12.06667 12.08584 12.10540 12.12536 12.14569 12.16641 12.18750 12.20891
## [681] 12.23060 12.25259 12.27489 12.29751 12.32047 12.34377 12.36744 12.39148
## [689] 12.41592 12.44075 12.46600 12.49167 12.51779 12.54436 12.57140
#assign fits to a vector
both_trendc <- fit_bothc
#extract y min and max for each
limits_bothc <- ggplot_build(extract_bothc)$data
## `geom_smooth()` using formula 'y ~ x'
limits_bothc <- as.data.frame(limits_bothc)
both_yminc <- limits_bothc$ymin
both_ymaxc <- limits_bothc$ymax
#reassign dataframes (just to be safe)
work_bothc <- wrfc_both
#fill in missing dates to smooth fits
work_bothc <- work_bothc %>% complete(date = seq(min(date), max(date), by = "1 day"))
date_vec_bothc <- work_bothc$date
#create a new smooth dataframe to layer
smooth_frame_bothc <- data.frame(date_vec_bothc, both_trendc, both_yminc, both_ymaxc)
#WRF C
#plot smooth frames
p_wrf_c <- plotly::plot_ly() %>%
plotly::add_lines(x = ~date_vec_bothc, y = ~both_trendc,
data = smooth_frame_bothc,
hoverinfo = "text",
text = ~paste('</br> Date: ', date_vec_bothc,
'</br> Median Log Copies: ', round(both_trendc, digits = 2)),
line = list(color = '#E7298A', size = 8, opacity = 0.65),
showlegend = FALSE) %>%
layout(xaxis = list(range = c(mindate - 7, maxdate + 7))) %>% #buffer here
plotly::add_ribbons(x ~date_vec_bothc, ymin = ~both_yminc, ymax = ~both_ymaxc,
showlegend = FALSE,
opacity = 0.25,
hoverinfo = "text",
text = ~paste('</br> Date: ', date_vec_bothc, #leaving in case we want to change
'</br> Max Log Copies: ', round(both_ymaxc, digits = 2),
'</br> Min Log Copies: ', round(both_yminc, digits = 2)),
name = "",
fillcolor = '#E7298A',
line = list(color = '#E7298A')) %>%
layout(yaxis = list(title = "Total Log10 SARS CoV-2 Copies",
showline = TRUE,
automargin = TRUE)) %>%
layout(xaxis = list(title = "Date")) %>%
layout(title = "WRF C") %>%
plotly::add_markers(x = ~date, y = ~log_total_copies_both,
data = wrfc_both,
hoverinfo = "text",
showlegend = FALSE,
text = ~paste('</br> Date: ', date,
'</br> Actual Log Copies: ', round(log_total_copies_both, digits = 2)),
marker = list(color = '#E7298A', size = 6, opacity = 0.65))
p_wrf_c
save(p_wrf_c, file = "./plotly_objs/p_wrf_c.rda")
save(wrfa_both, file = "./plotly_objs/wrfa_both.rda")
save(wrfb_both, file = "./plotly_objs/wrfb_both.rda")
save(wrfc_both, file = "./plotly_objs/wrfc_both.rda")
save(date_vec_botha, file = "./plotly_objs/date_vec_botha.rda")
save(date_vec_bothb, file = "./plotly_objs/date_vec_bothb.rda")
save(date_vec_bothc, file = "./plotly_objs/date_vec_bothc.rda")
save(both_ymina, file = "./plotly_objs/both_ymina.rda")
save(both_ymaxa, file = "./plotly_objs/both_ymaxa.rda")
save(both_yminb, file = "./plotly_objs/both_yminb.rda")
save(both_ymaxb, file = "./plotly_objs/both_ymaxb.rda")
save(both_yminc, file = "./plotly_objs/both_yminc.rda")
save(both_ymaxc, file = "./plotly_objs/both_ymaxc.rda")